package com.lcy.ex;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class LcyExActivity extends Activity{
    /** Called when the activity is first created. */
	
	/** Variance **/
	int m_nClockCount = 0;
	int m_nMainCount = 0;
	private static final String ThreadMSG = "MyMSG";
	TextView m_tvClockCount;
	TextView m_tvMainCount;
	Button m_btnStart;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        m_tvClockCount = (TextView)findViewById(R.id.TV_CLOCK);
        m_tvMainCount = (TextView)findViewById(R.id.TV_MAIN);
        m_btnStart = (Button)findViewById(R.id.BTN_START);
        
        m_btnStart.setOnClickListener(BTN_START);
        
        Clock clock = new Clock();
        clock.setDaemon(true);
        clock.start();
        
    }


	public View.OnClickListener BTN_START = new View.OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			m_nMainCount++;
			m_tvClockCount.setText("Clock"+m_nClockCount);
			m_tvMainCount.setText("Main :"+m_nMainCount);
		}
	};
	
	class Clock extends Thread{
		public void run(){
			while(true){
				m_nClockCount++;
				try{
					Thread.sleep(1000);
				}catch(InterruptedException e){
					Log.e(ThreadMSG, e.toString());
				}
			}
		}
	}
}

